package com.cusc.module_monitor_location.utils;

import android.annotation.SuppressLint;
import android.widget.ImageView;

import androidx.annotation.IdRes;
import androidx.databinding.BindingAdapter;

import com.chad.library.adapter.base.entity.node.BaseNode;
import com.cusc.lib_api.bean.department.NodeDepartment;
import com.cusc.module_monitor_location.R;
import com.cusc.module_monitor_location.entry.NodeBean;

import java.util.ArrayList;

/**
 * 作者: wangfei
 * 创建时期: 2020/4/14.
 * 包名: com.cusc.module_monitor_location.utils
 * 类名: OSAndroidMvvm
 */
public class DepartmentUtils {


    @SuppressLint("ResourceType")
    @BindingAdapter({"android:src"})
    public static @IdRes int TitleImage(ImageView imageView, int nodeType){
        switch (nodeType){
            case 1:
                imageView.setImageResource(R.drawable.choose_sys);
                break;
            case 2:
                imageView.setImageResource(R.drawable.choose_department);
                break;
            case 3:
                imageView.setImageResource(R.drawable.choose_car);
                break;
            case 4:
                imageView.setImageResource(R.drawable.choose_person);
                break;
        }

        return 0;
    }

    public static ArrayList<NodeBean> ConvertNodeBean(ArrayList<NodeDepartment> list){
        ArrayList<NodeBean> convertList = new ArrayList<>();
        for (int i = 0;i<list.size();i++){
            NodeDepartment department = list.get(i);
            ArrayList<NodeDepartment> childParentList = list.get(i).getChildren();
            NodeBean nodeBean = new NodeBean(department.getText(),
                    department.getId(),department.getLeaf(),department.getNodeType());
            if (childParentList!= null && childParentList.size()>0){
                ArrayList<BaseNode> childList = new ArrayList();
                for (int j = 0;j < childParentList.size(); j++){
                    NodeDepartment child_department = childParentList.get(i);
                    NodeBean childNodeBean = new NodeBean(child_department.getText(),
                            child_department.getId(),child_department.getLeaf(),child_department.getNodeType());
                    childList.add(childNodeBean);
                }
                nodeBean.setChildNode(childList);
            }
            convertList.add(nodeBean);
        }
        return convertList;
    }

    public ArrayList<NodeBean> UpdateUiState(ArrayList<NodeBean> list,int position){
        for (int i = 0; i < list.size() ; i++){

        }

        return null;
    }


}
